package com.company;

import com.company.builder.ConreteBuilder;
import com.company.builder.Director;
import com.company.builder.Product;
import com.company.builderGameRole.*;
import com.company.decorative.Beef;
import com.company.decorative.Fans;
import com.company.factory.*;
import com.company.fcade.EncryptFacade;
import com.company.instance.InstanceTest;
import com.company.instance.InstanceTest1;
import com.company.instance.InstanceTest2;
import com.company.observe.Cat;
import com.company.observe.Dog;
import com.company.observe.MySubject;
import com.company.observe.People;
import com.company.prototype.孙悟空;
import com.company.state.StateModeTest;

public class Main {

    public static void main(String[] args) {
        // write your code here

        //单例模式
        System.out.println(InstanceTest.getInstance().toString());
        System.out.println(InstanceTest1.getInstance().toString());
        System.out.println(InstanceTest2.getInstance().toString());

        //反射工厂
        Fruit peer = (Peer) MyFactory.getInstance().getObject("Peer");
        String name = peer.getName();
        System.out.println(name);
        Fruit apple = (Apple) MyFactory.getInstance().getObject("Apple");
        String name1 = apple.getName();
        System.out.println(name1);

        //简单工厂
        peer = (Peer) SimpleFactory.getInstance().getObject("Peer");
        name = peer.getName();
        System.out.println(name);
        apple = (Apple) SimpleFactory.getInstance().getObject("Apple");
        name1 = apple.getName();
        System.out.println(name1);

        //观察者模式
        MySubject myObserve = new MySubject();
        Cat cat = new Cat();
        Dog dog = new Dog();
        People people = new People();

        myObserve.register(cat);
        myObserve.register(dog);
        myObserve.register(people);
        myObserve.update();

        //装饰模式
        Beef beef = new Beef();
        Fans fans = new Fans();
        fans.addComponent(beef);
        Beef beef1 = new Beef();
        beef.addComponent(beef1);
        System.out.println("米粉价格:" + fans.getPrice() + "");

        //原型模式
        孙悟空 monkey = new 孙悟空();
        孙悟空 monkey1 = monkey.clone();
        monkey1.setAge(10);
        孙悟空 monkey2 = monkey1.clone();
        monkey1.setAge(20);
        System.out.println(monkey.getAge());
        System.out.println(monkey1.getAge());
        System.out.println(monkey2.getAge());


        //建造者模式
        System.out.println("创造者模式");
        ConreteBuilder conreteBuilder = new ConreteBuilder();
        Director director = new Director(conreteBuilder);
        Product product = director.createProduct();
        System.out.println(product);

        //建造者模式
        System.out.println("游戏角色创建");
        AnagleBuiler anagleBuiler = new AnagleBuiler();
        HeroBuilder heroBuilder = new HeroBuilder();
        DevilBuilder devilBuilder = new DevilBuilder();

        RoleController roleController = new RoleController();
        Role role = roleController.builerRole(anagleBuiler);
        role = roleController.builerRole(heroBuilder);
        role = roleController.builerRole(devilBuilder);

        //外观模式
        EncryptFacade ef = new EncryptFacade();
        ef.fileEncrypt("test.file", "des.file");

        System.out.println("外观模式");
        //状态模式
        StateModeTest stateModeTest=new StateModeTest();
        stateModeTest.run();



    }
}
